package org.dce.screencapturer.objects;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Stroke;

public class ShadowAttributes 
	extends PaintAttributes{

	private int offsetX = 10;
	private int offsetY = 10;
	
	private Stroke currentStroke;
	
	public ShadowAttributes(){
		setEnabled(true);
		setTransparency(80);
	}
	
	public ShadowAttributes(boolean enabled, int transparency, int offsetX, int offsetY){
		setEnabled(enabled);
		setTransparency(transparency);
		this.offsetX = offsetX;
		this.offsetY = offsetY;
	}
	
	public int getOffsetX() {
		return offsetX;
	}
	public void setOffsetX(int offsetX) {
		this.offsetX = offsetX;
	}
	public int getOffsetY() {
		return offsetY;
	}
	public void setOffsetY(int offsetY) {
		this.offsetY = offsetY;
	}
	
	@Override
	public void apply(Graphics2D g2d) {
		
		currentStroke = g2d.getStroke();

		g2d.setStroke(new BasicStroke(5));
		g2d.translate(offsetX, offsetY);
		
	}
	@Override
	public void restore(Graphics2D g2d) {
		
		g2d.setStroke(currentStroke);
		g2d.translate(-offsetX,-offsetY);
		
		super.restore(g2d);
	}

	@Override
	public Insets getInsets() {
		
		return new Insets(
			offsetY < 0 ? -offsetY : 0,
			offsetX < 0 ? -offsetX : 0,
			offsetY > 0 ? offsetY : 0,
			offsetX > 0 ? offsetX : 0);
	}

	public Object clone(){
		return new ShadowAttributes(isEnabled(), getTransparency(), offsetX, offsetY);
	}
}
